

/**
 * 
 */

/**
 * @author zero
 *
 */
public class ShapeLogic
{
    public boolean isBetweenWall()
    {
        return false;
    }

    public boolean isOutLeft(Shape shape)
    {
        return shape.getLeftestBlockX() < GameProperty.LEFT;
    }

    public boolean isOutRight(Shape shape)
    {

        return shape.getRightestBlockX() > GameProperty.RIGHT;
    }

    public boolean isTouchBottom(GameContext gc, Shape shape)
    {
        return false;
    }

    public void onMoveLeft()
    {

    }

    public void onMoveRight()
    {

    }

    public void onMoveDown()
    {

    }

    public void onClipse()
    {

    }

    public void nextRound()
    {

    }

    public void nextStep(GameContext gc, Shape shape)
    {
        int touchPostion = testTouchBottom(gc, shape);
        if (touchPostion == GameProperty.INVALIDE_POS)
        {
            shape.moveDown();
            return;
        }
        else
        {
            onTouchBottom(gc, shape, touchPostion);
        }
    }

    public int testTouchBottom(GameContext gc, Shape shape)
    {
        int x = shape.getX();
        int width = shape.getWidth();

        for (int i = x; i < x + width; i++)
        {
            int curHeight = gc.getHeightInX(i);
            int blockHeight = shape.getLowestBlockYByX(i);
            if (curHeight + 1 <= blockHeight)
            {
                return i;
            }
        }

        return GameProperty.INVALIDE_POS;
    }

    public void onTouchBottom(GameContext gc, Shape shape, int position)
    {
        Shape[] shapes = shape.devideIntoShapes(position);
        Shape shapeLeft = shapes[0];
        Shape shapeRight = shapes[2];
        Shape shapeMid = shapes[1];

        if (null != shapeLeft)
        {
            gc.addFallingShape(shapeLeft);
        }

        if (null != shapeRight)
        {
            gc.addFallingShape(shapeRight);
        }

        gc.delFallingShape(shapeMid);
    }

    public void onChangeShape()
    {

    }

    public void testBlockToClear()
    {

    }

    public void onBlockToClear()
    {

    }

    public void onClearEnd()
    {

    }

    public void onFillWhole()
    {

    }

    public void searchBiggerBlock()
    {

    }

    public void fall()
    {

    }

    public void go(GameContext gc)
    {
        nextRound();





    }
}
